# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  https://gitee.com/autumner/pythoncookbook
@software: PyCharm 
@file: net_urllib_post.py 
@time: 2019/7/10 上午11:13
"""
'''
web中POST方法请求
'''
from urllib import request, parse

# 设置URL
url = 'http://httpbin.org/post'

# 设置参数
params = {
    'username' : 'zhangsan',
    'address' : 'China.Tianj'
}

# 参数转码
querystring = parse.urlencode(params)

# 发送POST请求并返回结果
u = request.urlopen(url, querystring.encode('ascii'))
resp = u.read()
print(resp)